<template>
  <div>
    <div class="ibox-content no-border">
      配置管理员角色：{{adminDetails.real_name}}
    </div>
    <div class="ibox-content">
      <el-button size="small" type="primary" plain icon="el-icon-folder" @click.native="addRole('addForm')">添加
      </el-button>
      <el-button @click="goBack" size="small" type="primary" plain icon="el-icon-back">返回列表</el-button>
    </div>
    <div class="ibox-content">
      <el-radio-group v-model="adminDetails.role_name">
        <el-radio :key="index" :label="key" v-for="(item,key,index) in roleListOption">{{item.name}}</el-radio>
      </el-radio-group>
    </div>
    <div class="ibox-content">
      <el-button size="small" type="primary" plain icon="el-icon-folder" @click.native="addRole('addForm')">添加
      </el-button>
      <el-button @click="goBack" size="small" type="primary" plain icon="el-icon-back">返回列表</el-button>
    </div>
  </div>
</template>

<script>
  import {setAdminRoal, getRoleListOption, adminDetails} from "../../api/admin";

  export default {
    name: "SettingAdminRole",
    data() {
      return {
        roleListOption: [],
        adminDetails: {}
      }
    },
    created() {
      this.getAdminDetails();
      this.getRoleListOption();
    },
    methods: {
      getAdminDetails() {
        adminDetails({
          data_code: this.$route.query.code
        }).then(res => {
          this.adminDetails = res.data;
        })
      },
      getRoleListOption() {
        getRoleListOption({}).then(res => {
          this.roleListOption = res.data;
        }).catch(error => {
          
        })
      },
      addRole() {
        if (this.adminDetails.role_name) {
          setAdminRoal({
            data_code: this.adminDetails.data_code,
            item_name: this.adminDetails.role_name
          }).then(res => {
            this.$message.success(res.msg)
          })
        } else {
          this.$message.error('请选择角色')
        }
      },
      goBack() {
        this.$router.push({name: 'Admin'})
      }
    },
  }
</script>

<style scoped>

</style>
